package com.fractalist.man.web.action;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fractalist.base.cache.Cache;
import com.fractalist.base.core.constants.SystemConstants;
import com.fractalist.base.core.model.JsonSuccessResponse;
import com.fractalist.base.core.utils.MD5Util;
import com.fractalist.base.core.utils.MyDateUtils;
import com.fractalist.base.core.utils.MyImageUtils;
import com.fractalist.base.core.web.BaseActionSupport;
import com.fractalist.man.base.Page;
import com.fractalist.man.base.SqlUtils;
import com.fractalist.man.constants.ManConstants;
import com.fractalist.man.service.IAdsService;
import com.fractalist.man.service.IAlbumsService;
import com.fractalist.man.service.IAnswerService;
import com.fractalist.man.service.IArticleCollectionService;
import com.fractalist.man.service.IArticleColumnService;
import com.fractalist.man.service.IArticleFieldService;
import com.fractalist.man.service.IArticleService;
import com.fractalist.man.service.ICommentService;
import com.fractalist.man.service.ICompetenciaRoleService;
import com.fractalist.man.service.ICompetenciaService;
import com.fractalist.man.service.IFilterService;
import com.fractalist.man.service.IFmService;
import com.fractalist.man.service.IImageService;
import com.fractalist.man.service.IQuestService;
import com.fractalist.man.service.IQuestionService;
import com.fractalist.man.service.IScoreRuleService;
import com.fractalist.man.service.ISplashScreenService;
import com.fractalist.man.service.ITagsService;
import com.fractalist.man.service.IUserApplyService;
import com.fractalist.man.service.IUserAttentionService;
import com.fractalist.man.service.IUserFieldService;
import com.fractalist.man.service.IUserGroupService;
import com.fractalist.man.service.IUserService;
import com.fractalist.man.service.IVersionService;
import com.fractalist.man.service.IViewBangdanService;
import com.fractalist.man.service.IViewBasearticleUnionService;
import com.fractalist.man.service.IViewBaseuserUnionService;
import com.fractalist.man.service.IViewCommentService;
import com.fractalist.man.service.IVoteService;

@Controller
@Scope("prototype")
@ParentPackage("default")
@Namespace(value = "/")
@Action(value = "manager")
public class ManagerAction extends BaseActionSupport {

	private static final long serialVersionUID = -2111808911345170917L;

	private static final Logger logger = Logger.getLogger(ManagerAction.class);

	@Autowired
	private ISplashScreenService splashScreenService;
	@Autowired
	private IUserService userService;
	@Autowired
	private IAlbumsService albumsService;
	// @Autowired
	// private IAlbumsImageService albumsImageService;
	@Autowired
	private IArticleService articleService;
	@Autowired
	private IUserAttentionService userAttentionService;
	@Autowired
	private IFmService fmService;
	@Autowired
	private IArticleCollectionService articleCollectionService;
	@Autowired
	private ICommentService commentService;
	@Autowired
	private IFilterService filterService;
	@Autowired
	private IQuestionService questionService;
	@Autowired
	private IAnswerService answerService;
	@Autowired
	private IVersionService versionService;
	// @Autowired
	// private IArticleImageService articleImageService;
	@Autowired
	private IViewBangdanService viewBangdanService;
	@Autowired
	private IUserApplyService userApplyService;
	@Autowired
	private IViewCommentService viewCommentService;
	@Autowired
	private IQuestService questService;
	@Autowired
	private IScoreRuleService scoreRuleService;
	@Autowired
	private ITagsService tagsService;
	@Autowired
	private ICompetenciaRoleService competenciaRoleService;
	@Autowired
	private ICompetenciaService competenciaService;
	@Autowired
	private IUserFieldService userFieldService;
	@Autowired
	private IArticleFieldService articleFieldService;
	@Autowired
	private IViewBasearticleUnionService viewBasearticleUnionService;
	@Autowired
	private IViewBaseuserUnionService viewBaseuserUnionService;
	@Autowired
	private IUserGroupService userGroupService;
	@Autowired
	private IImageService imageService;
	@Autowired
	private IArticleColumnService articleColumnService;
	@Autowired
	private IVoteService voteService;
	@Autowired
	private IAdsService adsService;

	private Map<String, Object> paramMap;

	private String expire = "0mn";

	private String userName;
	private String password;

	private Long userId;
	private String name;
	private Integer gender;
	private Integer age;
	private String bwh;
	private String constellation;

	private String phoneNumber;
	private String platform;

	private Integer pageNumber = 1;
	private Integer pageLine = ManConstants.COMMON_PAGE_SIZE;
	private Integer state;

	private String image;
	private String fomart;
	private String[] images;

	private Long albumId;
	private String summary;

	private Long followUserId;
	private Boolean value;

	private Long columnId;

	private Long articleId;
	private String content;

	private Long questionId;

	private String endDate;
	private String startDate;

	private File fujianFile;

	private String fujianFileFileName;

	private String fujianFileContentType;
	private String uploadFileURL;
	private String uploadFileName;
	private Integer uploadFileSize;

	private String title;
	private String imgStr;
	private String imgPath;
	private String imgSummaryStr;
	private String oldpwd;
	private String newpwd;

	private String userType;
	private String publishType;
	private String publishTime;
	private String userState;
	private String girlCity;

	private String createDate;
	private String score;
	private String girlWeight;
	private String girlPkWeight;

	private Integer type;
	private Integer days;
	private String zhuangnvlangList;

	private Long applyId;
	private Long fmId;
	private String fmUrl;

	private String staticOrderType = "collect";
	private Long commentId;
	private Long questId;
	private String desc;
	private Integer questProcess;
	private Long scoreRuleId;

	private String iconUrl, imageUrl, pkImageUrl, pkBigImageUrl;

	private Long tagId;

	private String columnName;

	private Integer bust;
	private Integer waistline;
	private Integer hip;

	private Long adsId;
	private String adsClass;
	private String adsUrl;
	private String adsHtml;
	private String adsPic;

	private String tags;

	private Integer questionType;

	private Long userGroupId;
	private String userGroupName;

	private Long filterId;
	private String filterKeyStr;

	private String scoreRuleName;
	private String scoreRuleAction;

	MyImageUtils imageUtils = new MyImageUtils();

	/**
	 * 功能：Java读取txt文件的内容 步骤：1：先获得文件句柄 2：获得文件句柄当做是输入一个字节码流，需要对这个输入流进行读取
	 * 3：读取到输入流后，需要读取生成字节流 4：一行一行的输出。readline()。 备注：需要考虑的是异常情况
	 * 
	 * @param filePath
	 */
	public List<String> readTxtFile(String filePath) {
		List<String> list = new ArrayList<String>();
		File file = null;
		InputStreamReader read = null;
		try {
			String encoding = "utf-8";
			file = new File(filePath);
			if (file.isFile() && file.exists()) { // 判断文件是否存在
				read = new InputStreamReader(new FileInputStream(file),
						encoding);// 考虑到编码格式
				BufferedReader bufferedReader = new BufferedReader(read);
				String lineTxt = null;
				while ((lineTxt = bufferedReader.readLine()) != null) {
					if (!StringUtils.isEmpty(lineTxt)) {
						list.add(lineTxt);
					}
				}
				bufferedReader.close();
			} else {
				logger.debug("找不到指定的文件");
			}
		} catch (Exception e) {
			logger.debug("读取文件内容出错");
			e.printStackTrace();
		} finally {
			try {
				if (read != null) {
					read.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return list;
	}

	/**
	 * 创建文件
	 * 
	 * @throws IOException
	 */
	public boolean creatTxtFile(String name) {
		boolean flag = false;
		File filename = new File(name);
		if (!filename.exists()) {
			try {
				filename.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
			flag = true;
		}
		return flag;
	}

	/**
	 * 写文件
	 * 
	 * @param newStr
	 *            新内容
	 * @throws IOException
	 */
	public boolean writeTxtFile(String filenameTemp, String newStr) {
		// + "\r\n"
		// 先读取原有文件内容，然后进行写入操作
		boolean flag = false;
		String filein = newStr;
		FileInputStream fis = null;
		InputStreamReader isr = null;
		BufferedReader br = null;

		FileOutputStream fos = null;
		OutputStreamWriter osw = null;
		try {
			// 文件路径
			File file = new File(filenameTemp);
			// 将文件读入输入流
			fis = new FileInputStream(file);
			isr = new InputStreamReader(fis);
			br = new BufferedReader(isr);
			StringBuffer buf = new StringBuffer();
			buf.append(filein);
			fos = new FileOutputStream(file);
			osw = new OutputStreamWriter(fos, "UTF-8");
			osw.write(newStr);
			osw.flush();
			flag = true;
		} catch (IOException e1) {
			e1.printStackTrace();
		} finally {
			try {
				if (osw != null) {
					osw.close();
				}
				if (fos != null) {
					fos.close();
				}
				if (br != null) {
					br.close();
				}
				if (isr != null) {
					isr.close();
				}
				if (fis != null) {
					fis.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return flag;
	}

	// TODO
	// action开始

	/**
	 * 查看创建积分策略
	 */
	@Action(value = "/viewScroeRule", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewScroeRule() {
		if (scoreRuleId != null) {
			getRequest().setAttribute("scoreRule",
					scoreRuleService.queryById(scoreRuleId));
		}
		return dispatcher("/scoreRule.jsp");
	}

	/**
	 * 创建一个积分策略
	 */
	@Action(value = "/createScroeRule", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String createScroeRule() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("name", scoreRuleName);
		paramMap.put("score", score);
		paramMap.put("action", scoreRuleAction);
		paramMap.put("createDate",
				MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
		if (scoreRuleId == null) {
			scoreRuleId = scoreRuleService.add(SqlUtils.genderInsertSql(
					scoreRuleService.getTableName(), paramMap));
		} else {
			// 更新
			scoreRuleService.update(SqlUtils.genderUpdateSql(
					scoreRuleService.getTableName(), "id = " + scoreRuleId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
		}
		Cache.removeKeyByContainStr(scoreRuleService.getTableName());
		JsonSuccessResponse res = new JsonSuccessResponse();
		res.getData().put("code", "0");
		return renderJson(res);
	}

	/**
	 * 删除积分策略
	 */
	@Action(value = "/delScroeRule", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String delScroeRule() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (scoreRuleId == null) {
			result.put("state", -4201);
			result.put("msg", "积分策略id不能为空");
		} else {
			scoreRuleService.excute("delete from "
					+ scoreRuleService.getTableName() + " where id = "
					+ scoreRuleId);
			Cache.removeKeyByContainStr(scoreRuleService.getTableName());
			result.put("state", 0);
			result.put("msg", "已删除");
		}
		return renderJson(result);
	}

	/**
	 * 进入积分策略列表分页
	 */
	@Action(value = "/viewScroeRulePage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewScroeRulePage() {
		return dispatcher("/scoreRuleList.jsp");
	}

	/**
	 * 获取积分策略分页的json
	 */
	@Action(value = "/mScroeRulePage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mScroeRulePage() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		String sqls = SqlUtils.genderQuerySql(scoreRuleService.getTableName(),
				SqlUtils.genderConditionsByType(paramMap, "and"));
		Page page = new Page(pageNumber, pageLine, sqls, expire,
				scoreRuleService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 查看创建用户分组
	 */
	@Action(value = "/viewCreateUserGroup", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewCreateUserGroup() {
		if (userGroupId != null) {
			getRequest().setAttribute(
					"userGroup",
					userGroupService.queryOneRow("select * from "
							+ userGroupService.getTableName()
							+ " where groupId = " + userGroupId));
		}
		return dispatcher("/userGroup.jsp");
	}

	/**
	 * 创建一个用户分组
	 */
	@Action(value = "/createUserGroup", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String createUserGroup() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("groupName", userGroupName);
		paramMap.put("type", type == null ? ManConstants.USERGROUP_TYPE_BACK
				: type);
		if (userGroupId == null) {
			userGroupId = userGroupService.add(SqlUtils.genderInsertSql(
					userGroupService.getTableName(), paramMap));
		} else {
			// 更新
			userGroupService.update(SqlUtils.genderUpdateSql(
					userGroupService.getTableName(),
					"groupId = " + userGroupId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
		}
		Cache.removeKeyByContainStr(userGroupService.getTableName());
		JsonSuccessResponse res = new JsonSuccessResponse();
		res.getData().put("code", "0");
		return renderJson(res);
	}

	/**
	 * 禁用用户分组
	 */
	@Action(value = "/failUserGroup", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String failUserGroup() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (userGroupId == null) {
			result.put("state", -4101);
			result.put("msg", "用户分组id不能为空");
		} else {
			userGroupService.update("update " + userGroupService.getTableName()
					+ " set state = " + ManConstants.USERGROUP_STATE_FAIL
					+ " where groupId = " + userGroupId);
			Cache.removeKeyByContainStr(userGroupService.getTableName());
			result.put("state", 0);
			result.put("msg", "操作成功");
		}
		return renderJson(result);
	}

	/**
	 * 取消禁用用户分组
	 */
	@Action(value = "/okUserGroup", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String okUserGroup() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (userGroupId == null) {
			result.put("state", -4101);
			result.put("msg", "用户分组id不能为空");
		} else {
			userGroupService.update("update " + userGroupService.getTableName()
					+ " set state = " + ManConstants.USERGROUP_STATE_OK
					+ " where groupId = " + userGroupId);
			Cache.removeKeyByContainStr(userGroupService.getTableName());
			result.put("state", 0);
			result.put("msg", "操作成功");
		}
		return renderJson(result);
	}

	/**
	 * 删除用户分组
	 */
	@Action(value = "/delUserGroup", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String delUserGroup() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (userGroupId == null) {
			result.put("state", -4001);
			result.put("msg", "用户分组id不能为空");
		} else {
			userGroupService.excute("delete from "
					+ userGroupService.getTableName() + " where groupId = "
					+ userGroupId);
			Cache.removeKeyByContainStr(userGroupService.getTableName());
			result.put("state", 0);
			result.put("msg", "已删除");
		}
		return renderJson(result);
	}

	/**
	 * 进入用户分组列表分页
	 */
	@Action(value = "/viewUserGroupPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewUserGroupPage() {
		return dispatcher("/userGroupList.jsp");
	}

	/**
	 * 获取用户分组分页的json
	 */
	@Action(value = "/mUserGroupPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mUserGroupPage() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		String sqls = SqlUtils.genderQuerySql(userGroupService.getTableName(),
				SqlUtils.genderConditionsByType(paramMap, "and"));
		Page page = new Page(pageNumber, pageLine, sqls, expire,
				userGroupService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 查看创建广告
	 */
	@Action(value = "/viewCreateAds", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewCreateAds() {
		if (adsId != null) {
			getRequest().setAttribute("ads", adsService.queryById(adsId));
		}
		return dispatcher("/ads.jsp");
	}

	/**
	 * 创建一个广告
	 */
	@Action(value = "/createAds", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String createAds() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("type", type);
		paramMap.put("class", adsClass);
		paramMap.put("title", title);
		paramMap.put("url", adsUrl);
		paramMap.put("html", adsHtml);
		paramMap.put("pic", adsPic);
		if (adsId == null) {
			paramMap.put("listOrder", 0);
			paramMap.put("state", 1);
			adsId = adsService.add(SqlUtils.genderInsertSql(
					adsService.getTableName(), paramMap));
		} else {
			// 更新
			adsService.update(SqlUtils.genderUpdateSql(
					adsService.getTableName(), "id = " + adsId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
		}
		Cache.removeKeyByContainStr(adsService.getTableName());
		JsonSuccessResponse res = new JsonSuccessResponse();
		res.getData().put("code", "0");
		return renderJson(res);
	}

	/**
	 * 删除广告
	 */
	@Action(value = "/delAds", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String delAds() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (adsId == null) {
			result.put("state", -3001);
			result.put("msg", "广告id不能为空");
		} else {
			adsService.excute("delete from " + adsService.getTableName()
					+ " where id = " + adsId);
			Cache.removeKeyByContainStr(adsService.getTableName());
			result.put("state", 0);
			result.put("msg", "已删除");
		}
		return renderJson(result);
	}

	/**
	 * 失效广告
	 */
	@Action(value = "/failAds", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String failAds() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (adsId == null) {
			result.put("state", -3001);
			result.put("msg", "广告id不能为空");
		} else {
			adsService.update("update " + adsService.getTableName()
					+ " set state = " + ManConstants.ADS_STATE_DIS
					+ " where id = " + adsId);
			Cache.removeKeyByContainStr(adsService.getTableName());
			result.put("state", 0);
			result.put("msg", "操作成功");
		}
		return renderJson(result);
	}

	/**
	 * 生效广告
	 */
	@Action(value = "/okAds", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String oksAds() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (adsId == null) {
			result.put("state", -3001);
			result.put("msg", "广告id不能为空");
		} else {
			adsService.update("update " + adsService.getTableName()
					+ " set state = " + ManConstants.ADS_STATE_OK
					+ " where id = " + adsId);
			Cache.removeKeyByContainStr(adsService.getTableName());
			result.put("state", 0);
			result.put("msg", "操作成功");
		}
		return renderJson(result);
	}

	/**
	 * 进入广告列表分页
	 */
	@Action(value = "/viewAdsPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewAdsPage() {
		return dispatcher("/adsList.jsp");
	}

	/**
	 * 获取广告列表分页的json
	 */
	@Action(value = "/mAdsPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mAdsPage() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		if (state != null) {
			paramMap.put("state", state);
		}
		if (!StringUtils.isEmpty(adsClass)) {
			paramMap.put("class", adsClass);
		}
		if (type != null) {
			paramMap.put("type", type);
		}
		String sqls = SqlUtils.genderQuerySql(adsService.getTableName(),
				SqlUtils.genderConditionsByType(paramMap, "and"));
		Page page = new Page(pageNumber, pageLine, sqls, expire, adsService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 查看权限列表
	 */
	@Action(value = "/viewCompetenciaPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewCompetenciaPage() {
		getRequest().setAttribute("userTypeMap", ManConstants.USER_TYPE_MAP);
		getRequest().setAttribute(
				"competenciaList",
				competenciaService
						.queryList("select * from man_base_competencia"));
		return dispatcher("/competenciaList.jsp");
	}

	/**
	 * 查看权限列表
	 */
	@Action(value = "/getCompetenciaRoleList", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String getCompetenciaRoleList() {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userType", userType);
		List<Map<String, Object>> crList = competenciaRoleService
				.queryList(SqlUtils.genderQuerySql("man_base_competencia_role",
						SqlUtils.genderConditionsByType(params, "and")));
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("crList", crList);
		return renderJson(resultMap);
	}

	/**
	 * 修改角色权限
	 */
	@Action(value = "/updateCompetenciaRole", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String updateCompetenciaRole() {
		String[] arr = desc.split(",");
		try {
			competenciaRoleService
					.excute("delete from man_base_competencia_role where userType = "
							+ userType);
			for (int i = 0; i < arr.length; i++) {
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("userType", userType);
				params.put("competenciaId", arr[i]);
				competenciaRoleService.add(SqlUtils.genderInsertSql(
						"man_base_competencia_role", params));
			}
		} catch (Exception e) {
			e.printStackTrace();
			Map<String, Object> resultMap = new HashMap<String, Object>();
			resultMap.put("code", -1);
			resultMap.put("msg", "操作失败");
			return renderJson(resultMap);
		}

		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("code", 0);
		resultMap.put("msg", "操作成功");
		return renderJson(resultMap);
	}

	// /**
	// * 获取标签列表分页的json
	// */
	// @Action(value = "/mTagPage", interceptorRefs =
	// @InterceptorRef("withAuthStack"))
	// public String mTagPage() {
	// Map<String, Object> paramMap = new HashMap<String, Object>();
	// String sqls = SqlUtils.genderQuerySql("man_base_tags",
	// SqlUtils.genderConditionsByType(paramMap, "and"));
	// Page page = new Page(pageNumber, pageLine, sqls, expire, tagsService);
	// return renderJson(page.getResultMap());
	// }

	/**
	 * 查看创建栏目
	 */
	@Action(value = "/viewCreateColumn", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewCreateColumn() {
		if (columnId != null) {
			Map<String, Object> column = articleColumnService
					.queryById(columnId);
			getRequest().setAttribute("column", column);
		}
		return dispatcher("/articleColumn.jsp");
	}

	/**
	 * 创建一个栏目
	 */
	@Action(value = "/createColumn", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String createColumn() {
		if (columnId == null) {
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("columnName", columnName);
			columnId = articleColumnService.add(SqlUtils.genderInsertSql(
					articleColumnService.getTableName(), paramMap));
		} else {
			// 更新
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("columnName", columnName);
			articleColumnService.update(SqlUtils.genderUpdateSql(
					articleColumnService.getTableName(), "id = " + columnId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
		}
		articleColumnService.resetConstantsMap();
		Cache.removeKeyByContainStr(articleColumnService.getTableName());
		JsonSuccessResponse res = new JsonSuccessResponse();
		res.getData().put("code", "0");
		return renderJson(res);
	}

	/**
	 * 进入标签列表分页
	 */
	@Action(value = "/viewColumnPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewColumnPage() {
		return dispatcher("/articleColumnList.jsp");
	}

	/**
	 * 获取标签列表分页的json
	 */
	@Action(value = "/mColumnPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mColumnPage() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		String sqls = SqlUtils.genderQuerySql(
				articleColumnService.getTableName(),
				SqlUtils.genderConditionsByType(paramMap, "and"));
		Page page = new Page(pageNumber, pageLine, sqls, expire,
				articleColumnService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 查看创建标签
	 */
	@Action(value = "/viewCreateTag", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewCreateTag() {
		if (tagId != null) {
			Map<String, Object> tag = tagsService.queryById(tagId);
			getRequest().setAttribute("tag", tag);
		}
		return dispatcher("/tag.jsp");
	}

	/**
	 * 创建一个标签
	 */
	@Action(value = "/createTag", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String createTag() {
		if (tagId == null) {
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("tagName", name);
			tagId = tagsService.add(SqlUtils.genderInsertSql("man_base_tags",
					paramMap));
		} else {
			// 更新
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("tagName", name);
			tagsService.update(SqlUtils.genderUpdateSql("man_base_tags",
					"id = " + tagId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
		}
		Cache.removeKeyByContainStr("man_base_tags");
		JsonSuccessResponse res = new JsonSuccessResponse();
		res.getData().put("code", "0");
		return renderJson(res);
	}

	/**
	 * 删除标签
	 */
	@Action(value = "/delTag", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String delTag() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (tagId == null) {
			result.put("state", -1);
			result.put("msg", "标签id不能为空");
		} else {
			tagsService.excute("delete from man_base_tags where id = " + tagId);
			Cache.removeKeyByContainStr("man_base_tags");
			result.put("state", 0);
			result.put("msg", "已删除");
		}
		return renderJson(result);
	}

	/**
	 * 进入标签列表分页
	 */
	@Action(value = "/viewTagPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewTagPage() {
		return dispatcher("/tagList.jsp");
	}

	/**
	 * 获取标签列表分页的json
	 */
	@Action(value = "/mTagPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mTagPage() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		String sqls = SqlUtils.genderQuerySql("man_base_tags",
				SqlUtils.genderConditionsByType(paramMap, "and"));
		Page page = new Page(pageNumber, pageLine, sqls, expire, tagsService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 查看创建任务
	 */
	@Action(value = "/viewCreateQuest", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewCreateQuest() {
		if (questId != null) {
			Map<String, Object> quest = questService.queryById(questId);
			getRequest().setAttribute("quest", quest);
		}
		return dispatcher("/quest.jsp");
	}

	/**
	 * 创建一个任务
	 */
	@Action(value = "/createQuest", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String createQuest() {
		String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
		if (questId == null) {
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("questName", title);
			paramMap.put("questDesc", desc);
			paramMap.put("score", score);
			paramMap.put("questUserType", userType);
			paramMap.put("questSiteType", type);
			paramMap.put("questProcessCount", questProcess);
			Map<String, Object> paramMap2 = new HashMap<String, Object>();
			paramMap2.put("score", score);
			paramMap2.put("action", "questCommonNull");
			paramMap2.put("name", title);
			paramMap2.put("createDate", now);
			scoreRuleId = scoreRuleService.add(SqlUtils.genderInsertSql(
					"man_base_score_rule", paramMap2));
			paramMap.put("scoreRuleId", scoreRuleId);
			questId = questService.add(SqlUtils.genderInsertSql(
					"man_base_quest", paramMap));
		} else {
			// 更新
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("questName", title);
			paramMap.put("questDesc", desc);
			paramMap.put("score", score);
			paramMap.put("questUserType", userType);
			paramMap.put("questSiteType", type);
			paramMap.put("questProcessCount", questProcess);
			scoreRuleService.update("update man_base_score_rule set score = "
					+ score + " where id = " + scoreRuleId);
			questService.update(SqlUtils.genderUpdateSql("man_base_quest",
					"id = " + questId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
		}
		Cache.removeKeyByContainStr("man_base_quest");
		Cache.removeKeyByContainStr("man_base_score_rule");
		JsonSuccessResponse res = new JsonSuccessResponse();
		res.getData().put("code", "0");
		return renderJson(res);
	}

	/**
	 * 删除任务
	 */
	@Action(value = "/delQuest", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String delQuest() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (questId == null) {
			result.put("state", -1);
			result.put("msg", "任务id不能为空");
		} else {
			questService.excute("delete from man_base_quest where id = "
					+ questId);
			Cache.removeKeyByContainStr("man_base_quest");
			result.put("state", 0);
			result.put("msg", "已删除");
		}
		return renderJson(result);
	}

	/**
	 * 进入任务列表分页
	 */
	@Action(value = "/viewQuestPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewQuestPage() {
		return dispatcher("/questList.jsp");
	}

	/**
	 * 获取任务列表分页的json
	 */
	@Action(value = "/mQuestPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mQuestPage() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		if (type != null) {
			paramMap.put("questSiteType", type);
		}
		String sqls = SqlUtils.genderQuerySql("man_base_quest",
				SqlUtils.genderConditionsByType(paramMap, "and"));
		Page page = new Page(pageNumber, pageLine, sqls, expire, questService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 进入举报列表分页
	 */
	@Action(value = "/viewAccusationPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewAccusationPage() {
		return dispatcher("/accusationList.jsp");
	}

	/**
	 * 获取举报列表分页的json
	 */
	@Action(value = "/mAccusationPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mAccusationPage() {
		// man_base_comment
		// man_view_comment
		Map<String, Object> paramMap = new HashMap<String, Object>();
		if (!StringUtils.isEmpty(startDate)) {
			paramMap.put("createDate >=", startDate);
		}
		if (!StringUtils.isEmpty(endDate)) {
			paramMap.put("createDate <", endDate);
		}
		if (columnId != null) {
			paramMap.put("columnId", columnId);
		}
		if (!StringUtils.isEmpty(publishType)) {
			paramMap.put("authorName like ", "%" + publishType + "%");
		}
		if (!StringUtils.isEmpty(title)) {
			paramMap.put("title like ", "%" + title + "%");
		}
		if (!StringUtils.isEmpty(name)) {
			paramMap.put("name like ", "%" + name + "%");
		}
		paramMap.put("types", ManConstants.ARTICLE_COMMENT_TYPE_ACCUSATION);

		String sqls = SqlUtils.genderQuerySql("man_view_comment",
				SqlUtils.genderConditionsByType(paramMap, "and"))
				+ " order by createDate desc";
		Page page = new Page(pageNumber, pageLine, sqls, expire,
				viewCommentService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 审核评论通过
	 */
	@Action(value = "/auditCommentOk", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String auditCommentOk() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (commentId == null) {
			result.put("state", -1);
			result.put("msg", "评论d不能为空");
		} else {
			commentService.update("update man_base_comment set state = "
					+ ManConstants.COMMENT_STATE_SUCCESS + " where id = "
					+ commentId);
			Cache.removeKeyByContainStr("man_base_comment");
			result.put("state", 0);
			result.put("msg", "已审核通过");
		}
		return renderJson(result);
	}

	/**
	 * 审核评论不通过
	 */
	@Action(value = "/auditCommentFail", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String auditCommentFail() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (commentId == null) {
			result.put("state", -1);
			result.put("msg", "评论d不能为空");
		} else {
			commentService.update("update man_base_comment set state = "
					+ ManConstants.COMMENT_STATE_FAIL + " where id = "
					+ commentId);
			Cache.removeKeyByContainStr("man_base_comment");
			result.put("state", 0);
			result.put("msg", "已审核为不通过");
		}
		return renderJson(result);
	}

	/**
	 * 进入评论列表分页
	 */
	@Action(value = "/viewCommentPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewCommentPage() {
		return dispatcher("/commentList.jsp");
	}

	/**
	 * 获取评论列表分页的json
	 */
	@Action(value = "/mCommentPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mCommentPage() {
		// man_base_comment
		// man_view_comment
		Map<String, Object> paramMap = new HashMap<String, Object>();
		if (!StringUtils.isEmpty(startDate)) {
			paramMap.put("createDate >=", startDate);
		}
		if (!StringUtils.isEmpty(endDate)) {
			paramMap.put("createDate <", endDate);
		}
		if (columnId != null) {
			paramMap.put("columnId", columnId);
		}
		if (!StringUtils.isEmpty(publishType)) {
			paramMap.put("name like ", "%" + publishType + "%");
		}
		paramMap.put("types", ManConstants.ARTICLE_COMMENT_TYPE_COMMENT);

		String sqls = SqlUtils.genderQuerySql("man_view_comment",
				SqlUtils.genderConditionsByType(paramMap, "and"))
				+ " order by createDate desc";
		Page page = new Page(pageNumber, pageLine, sqls, expire,
				viewCommentService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 进入收藏統計列表分页
	 */
	@Action(value = "/viewStaticsPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewStaticsPage() {
		return dispatcher("/staticsList.jsp");
	}

	/**
	 * 获取收藏統計列表分页的json
	 */
	@Action(value = "/mStaticsPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mStaticsPage() {
		if (!"praise".contains(staticOrderType)
				&& !"comments".contains(staticOrderType)
				&& !"collect".contains(staticOrderType)) {
			staticOrderType = "collect";
		}
		String sqls = "select a.*,u.name from man_view_basearticle_union as a,man_view_baseuser_union as u where a.authorId = u.userId  order by a."
				+ staticOrderType + " desc";
		Page page = new Page(pageNumber, pageLine, sqls, expire, articleService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 删除树洞问题
	 */
	@Action(value = "/delQuestion", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String delQuestion() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (questionId == null) {
			result.put("state", -1);
			result.put("msg", "问题id不能为空");
		} else {
			questionService.update("delete from man_base_question where id = "
					+ questionId);
			Cache.removeKeyByContainStr("man_base_question");
			result.put("state", 0);
			result.put("msg", "已删除");
		}
		return renderJson(result);
	}

	/**
	 * 进入树洞问题列表分页
	 */
	@Action(value = "/viewQuestionPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewQuestionPage() {
		if (questionType == null) {
			questionType = ManConstants.QUESTION_TYPE_SHUDONG;
		}
		getRequest().setAttribute("questionType", questionType);
		return dispatcher("/questionList.jsp");
	}

	/**
	 * 获取树洞问题列表分页的json
	 */
	@Action(value = "/mQuestionPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mQuestionPage() {
		if (questionType == null) {
			questionType = ManConstants.QUESTION_TYPE_SHUDONG;
		}
		String sqls = "select * from man_base_question where type = "
				+ questionType + " order by createDate desc";
		Page page = new Page(pageNumber, pageLine, sqls, expire,
				questionService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 查看创建电台节目
	 */
	@Action(value = "/viewCreateFm", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewCreateFm() {
		if (fmId != null) {
			Map<String, Object> fm = fmService.queryById(fmId);
			getRequest().setAttribute("fm", fm);
		}
		return dispatcher("/fm.jsp");
	}

	/**
	 * ajax上传电台节目的内容
	 */
	@Action(value = "/uploadFm", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String uploadFm() {
		JsonSuccessResponse res = new JsonSuccessResponse();
		int updateFileErrorCode = getFileFieldError();
		if (updateFileErrorCode > 0) {
			if (updateFileErrorCode == 1) {
				res.getData().put("code", "3");
				res.getData().put("message", "文件上传类型错误,系统只允许上传 mp3 格式的文件。");
			} else if (updateFileErrorCode == 2) {
				res.getData().put("code", "4");
				res.getData().put("message",
						"上传文件大小错误,系统最多只允许上传大小为100MB的附件，并且附件不能为null。");
			} else {
				res.getData().put("code", "5");
				res.getData().put("message", "上传文件失败,请与系统管理员联系。");
			}
			return renderJson(res);
		}
		String suffix = getFileSuffix(uploadFileName);
		if (!suffix.equals("mp3") && !suffix.equals("wav")) {
			res.getData().put("code", "3");
			res.getData().put("message", "文件上传类型错误,系统只允许上传 mp3,wav 格式的文件。");
			return renderJson(res);
		}

		res.getData().put("code", "0");
		res.getData().put("url", uploadFileURL);
		return renderJson(res);
	}

	/**
	 * 创建一个节目
	 */
	@Action(value = "/createFm", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String createFm() {
		String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
		if (fmId == null) {
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("title", title);
			paramMap.put("url", fmUrl);
			paramMap.put("iconUrl", iconUrl);
			paramMap.put("state", ManConstants.FM_STATE_UP);
			paramMap.put("createDate", now);
			fmId = fmService.add(SqlUtils.genderInsertSql("man_base_fm",
					paramMap));
		} else {
			// 更新
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("title", title);
			paramMap.put("url", fmUrl);
			paramMap.put("iconUrl", iconUrl);
			fmService.update(SqlUtils.genderUpdateSql("man_base_fm", "id = "
					+ fmId, SqlUtils.genderConditionsByType(paramMap, ",")));
		}
		Cache.removeKeyByContainStr("man_base_fm");
		JsonSuccessResponse res = new JsonSuccessResponse();
		res.getData().put("code", "0");
		return renderJson(res);
	}

	/**
	 * 删除电台节目
	 */
	@Action(value = "/delFm", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String delFm() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (fmId == null) {
			result.put("state", -1);
			result.put("msg", "节目id不能为空");
		} else {
			fmService.update("update man_base_fm set state = "
					+ ManConstants.FM_STATE_DEL + " where id = " + fmId);
			Cache.removeKeyByContainStr("man_base_fm");
			result.put("state", 0);
			result.put("msg", "已删除");
		}
		return renderJson(result);
	}

	/**
	 * 进入电台列表分页
	 */
	@Action(value = "/viewFmPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewFmPage() {
		return dispatcher("/fmList.jsp");
	}

	/**
	 * 获取电台列表分页的json
	 */
	@Action(value = "/mFmPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mFmPage() {
		String sqls = "select * from man_base_fm where state < "
				+ ManConstants.FM_STATE_DEL + " order by createDate desc";
		Page page = new Page(pageNumber, pageLine, sqls, expire, fmService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 进入过滤关键字列表分页
	 */
	@Action(value = "/viewFilterPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewFilterPage() {
		return dispatcher("/filterList.jsp");
	}

	/**
	 * 查看创建关键字
	 */
	@Action(value = "/viewCreateFilter", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewCreateFilter() {
		if (filterId != null) {
			Map<String, Object> filter = filterService.queryById(filterId);
			getRequest().setAttribute("filter", filter);
		}
		return dispatcher("/filter.jsp");
	}

	/**
	 * 创建一个关键字
	 */
	@Action(value = "/createFilter", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String createFilter() {
		if (filterId == null) {
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("keystr", filterKeyStr);
			filterId = filterService.add(SqlUtils.genderInsertSql(
					filterService.getTableName(), paramMap));
		} else {
			// 更新
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("keystr", filterKeyStr);
			filterService.update(SqlUtils.genderUpdateSql(
					filterService.getTableName(), "id = " + filterId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
		}
		Cache.removeKeyByContainStr(filterService.getTableName());
		JsonSuccessResponse res = new JsonSuccessResponse();
		res.getData().put("code", "0");
		return renderJson(res);
	}

	/**
	 * 获取过滤关键字列表分页的json
	 */
	@Action(value = "/mFilterPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mFilterPage() {
		String sqls = "select * from man_base_filter";
		Page page = new Page(pageNumber, pageLine, sqls, expire, filterService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 删除过滤字
	 */
	@Action(value = "/delFilter", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String delFilter() {
		if (filterId != null) {
			filterService.excute("delete from " + filterService.getTableName()
					+ " where id = " + filterId);
		}
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("state", "0");
		result.put("msg", "操作成功");
		return renderJson(result);
	}

	/**
	 * 导出过滤词到txt文件中，有默认的文件名和路径
	 */
	@Action(value = "/exportFilter", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String exportFilter() {
		String filenamestr = SystemConstants.UPLOAD_SERVER_PATH
				+ SystemConstants.FILTER_COMMON_NAME;
		creatTxtFile(filenamestr);
		List<Map<String, Object>> list = filterService
				.queryList("select * from man_base_filter");
		StringBuilder sb = new StringBuilder();
		for (Map<String, Object> f : list) {
			sb.append(f.get("keystr") + "\r\n");
		}
		writeTxtFile(filenamestr, sb.toString());
		JsonSuccessResponse res = new JsonSuccessResponse();
		res.getData().put("code", "0");
		res.getData().put(
				"url",
				URLEncoder.encode(filenamestr.replaceFirst(
						SystemConstants.UPLOAD_SERVER_PATH,
						SystemConstants.UPLOAD_WEB_URL)));
		return renderJson(res);
	}

	/**
	 * 上传过滤关键字的文件，txt格式
	 */
	@Action(value = "/importFilter", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String importFilter() {
		String suffix = getFileSuffix(uploadFileName);
		JsonSuccessResponse res = new JsonSuccessResponse();
		if (!suffix.equals("txt")) {
			res.getData().put("code", "10121");
			res.getData().put("message", "文件上传类型错误,系统只允许导入txt格式的文件。");
			return renderJson(res);
		}
		List<String> filterList = readTxtFile(uploadFileURL.replaceFirst(
				SystemConstants.UPLOAD_WEB_URL,
				SystemConstants.UPLOAD_SERVER_PATH));
		for (int i = 0; i < filterList.size(); i++) {
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("keystr", filterList.get(i));
			filterService.add(SqlUtils.genderInsertSql("man_base_filter",
					params));
		}
		Cache.removeKeyByContainStr("man_base_filter");
		res.getData().put("code", "0");
		res.getData().put("count", filterList.size());
		return renderJson(res);
	}

	/**
	 * 登陆
	 */
	@Action(value = "/viewLogin", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String viewLogin() {
		return dispatcher("/login.jsp");
	}

	/**
	 * 退出
	 */
	@Action(value = "/loginOut", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String loginOut() {
		getSession().removeAttribute(SystemConstants.USER_SESSION_KEY);
		return chain("/manage/viewLogin");
	}

	/**
	 * 登陆
	 */
	@Action(value = "/loginIn", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String loginIn() {
		if (StringUtils.isEmpty(userName)) {
			getRequest().setAttribute("errorCode", "1");
			getRequest().setAttribute("msg", "用户名不能为空");
			return dispatcher("/login.jsp");
		}
		if (StringUtils.isEmpty(password)) {
			getRequest().setAttribute("errorCode", "2");
			getRequest().setAttribute("msg", "密码不能为空");
			getRequest().setAttribute("userName", userName);
			return dispatcher("/login.jsp");
		}
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userName", userName);
		paramMap.put("password", MD5Util.getMD5Lower(password));
		logger.debug(paramMap);
		Map<String, Object> user = userService.queryOneRow(SqlUtils
				.genderQuerySql("man_view_baseuser_union",
						SqlUtils.genderConditionsByType(paramMap, " and ")));
		if (user != null && user.size() > 0) {
			if (!(user.get("state") + "").equals(ManConstants.USER_STATE_COMMON
					+ "")) {
				getRequest().setAttribute("errorCode", "4");
				getRequest().setAttribute("userName", userName);
				getRequest().setAttribute("msg", "账户状态异常，可能已被禁用，请联系管理员");
				return dispatcher("/login.jsp");
			}
			int userType = Integer.valueOf(user.get("groupId") + "");
			Map<String, Object> userGroup = userGroupService
					.queryOneRow("select * from "
							+ userGroupService.getTableName()
							+ " where groupId = " + userType);
			if (userGroup == null
					|| userGroup.size() == 0
					|| (userGroup.get("state") + "")
							.equals(ManConstants.USERGROUP_STATE_FAIL
									.toString())) {
				getRequest().setAttribute("errorCode", "6");
				getRequest().setAttribute("userName", userName);
				getRequest().setAttribute("msg",
						"抱歉，您的用户分组不存在或者已被禁用，无法登陆后台，如有疑问，请联系管理员");
				return dispatcher("/login.jsp");
			}
			// if (userType != ManConstants.USER_TYPE_DAREN.intValue()
			// && userType != ManConstants.USER_TYPE_ADMIN.intValue()) {
			// getRequest().setAttribute("errorCode", "5");
			// getRequest().setAttribute("userName", userName);
			// getRequest().setAttribute("msg",
			// "抱歉，您的用户身份目前无法登录后台，如有疑问，请联系管理员");
			// return dispatcher("/login.jsp");
			// }
			getSession().setAttribute(SystemConstants.USER_SESSION_KEY, user);
			// TODO 可以在这里根据用户的类型决定跳转地址，或者到前台，在jsp中判断也可以，这两者登陆后应该是有区别的
			getRequest()
					.setAttribute(
							"crList",
							competenciaRoleService
									.queryList("select c.* from man_base_competencia c,man_base_competencia_role r where r.userType = "
											+ userType
											+ " and r.competenciaId = c.id"));
			return dispatcher("/manager/index.action");
		}
		getRequest().setAttribute("errorCode", "3");
		getRequest().setAttribute("userName", userName);
		getRequest().setAttribute("msg", "用户名或密码错误");
		return dispatcher("/login.jsp");
	}

	/**
	 * 首页
	 */
	@SuppressWarnings("unchecked")
	@Action(value = "/index", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String index() {
		Map<String, Object> user = (Map<String, Object>) getRequest()
				.getSession().getAttribute(SystemConstants.USER_SESSION_KEY);
		if (user != null && user.size() > 0) {

		}
		return dispatcher("/indexs.jsp");
	}

	/**
	 * 进入文章列表分页
	 */
	@Action(value = "/viewArticlePage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewArticlePage() {
		getRequest().setAttribute("userId", userId == null ? "" : userId);
		return dispatcher("/articleList.jsp");
	}

	/**
	 * 获取文章列表分页的json
	 */
	@SuppressWarnings("unchecked")
	@Action(value = "/articlePage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String articlePage() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
		// if (startDate != null && startDate.trim().length() > 0) {
		// paramMap.put("a.createDate >=", startDate);
		// }
		// if (endDate != null && endDate.trim().length() > 0) {
		// paramMap.put("a.createDate <", endDate);
		// }
		if (columnId != null) {
			paramMap.put("a.columnId", columnId);
		}
		if (state != null) {
			// 此处进行逻辑上的处理，MBD，目前的状态有4个，其中除了待发布可以对上外，其他都属于已发布和已预约的范畴
			// <option value="1">已发布</option>
			// <option value="2">待发布</option>
			// <option value="3">已预约</option>
			if (state.intValue() == 1) {
				paramMap.put("a.state >", ManConstants.ARTICLE_STATE_COMMON);
				paramMap.put("a.publish_time <=", now);
			}
			if (state.intValue() == 2) {
				paramMap.put("a.state", ManConstants.ARTICLE_STATE_COMMON);
			}
			if (state.intValue() == 3) {
				paramMap.put("a.state >", ManConstants.ARTICLE_STATE_COMMON);
				paramMap.put("a.publish_time >", now);
			}
		}
		if (!StringUtils.isEmpty(publishType)) {
			paramMap.put("a.authorName like ", "%" + publishType + "%");
		}

		Map<String, Object> user = (Map<String, Object>) getSession()
				.getAttribute(SystemConstants.USER_SESSION_KEY);
		int userType = Integer.valueOf(user.get("groupId") + "");
		String addStr = "";
		// TODO 这里应该是能看到所有文章，达人是管理员
		// if (userId != null) {
		// paramMap.put("a.authorId", userId);
		// } else {
		// if (userType == ManConstants.USER_TYPE_DAREN.intValue()) {
		// addStr = " a.authorId = " + user.get("userId") + " and ";
		// }
		// }
		String sqls = "select a.*,u.name from "
				+ viewBasearticleUnionService.getTableName() + " as a,"
				+ userService.getTableName()
				+ " as u where a.authorId = u.userId and " + addStr
				+ SqlUtils.genderConditionsByType(paramMap, "and ")
				+ " order by a.top_time desc ,a.createDate desc";
		Page page = new Page(pageNumber, pageLine, sqls, expire,
				viewBasearticleUnionService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 查看创建文章页
	 */
	@Action(value = "/viewCreateArticle", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewCreateArticle() {
		if (articleId != null) {
			Map<String, Object> article = articleService.queryById(articleId);
			getRequest().setAttribute("article", article);
			List<Map<String, Object>> articleImageList = imageService
					.queryList(SqlUtils.genderQuerySql(
							imageService.getTableName(), "articleId = "
									+ articleId)
							+ " order by createDate desc");
			getRequest().setAttribute("articleImageList", articleImageList);
			getRequest().setAttribute(
					"baseTagList",
					tagsService.queryList("select * from "
							+ tagsService.getTableName()));
		}
		return dispatcher("/article.jsp");
	}

	/**
	 * 上传外部图片
	 */
	@Action(value = "/submitUrlImg", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String submitUrlImg() {
		JsonSuccessResponse res = new JsonSuccessResponse();
		// TODO 这个方法貌似目前没用到
		int updateFileErrorCode = getFileFieldError();
		if (updateFileErrorCode > 0) {
			if (updateFileErrorCode == 1) {
				res.getData().put("code", "3");
				res.getData().put("message",
						"文件上传类型错误,系统只允许上传 jpg,jpeg,gif,png 格式的文件。");
			} else if (updateFileErrorCode == 2) {
				res.getData().put("code", "4");
				res.getData().put("message",
						"上传文件大小错误,系统最多只允许上传大小为10MB的附件，并且附件不能为null。");
			} else {
				res.getData().put("code", "5");
				res.getData().put("message", "上传文件失败,请与系统管理员联系。");
			}
			return renderJson(res);
		}

		String suffix = getFileSuffix(uploadFileName);
		if (!suffix.equals("jpg") && !suffix.equals("jpeg")
				&& !suffix.equals("gif") && !suffix.equals("png")) {
			res.getData().put("code", "3");
			res.getData().put("message",
					"文件上传类型错误,系统只允许上传 jpg,jpeg,gif,png 格式的文件。");
			return renderJson(res);
		}

		if (uploadFileSize > (SystemConstants.FILE_UPLOAD_SIZE)) {
			res.getData().put("code", "4");
			res.getData().put(
					"message",
					"上传文件大小错误,系统最多只允许上传大小为" + SystemConstants.FILE_UPLOAD_SIZE
							+ "B的附件，并且附件不能为null。");
			return renderJson(res);
		}
		res.getData().put("code", "0");
		res.getData().put("url", uploadFileURL);
		return renderJson(res);
	}

	/**
	 * ajax上传图片
	 */
	@Action(value = "/uploadImgBase", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String uploadImgBase() {
		JsonSuccessResponse res = new JsonSuccessResponse();
		// TODO
		int updateFileErrorCode = getFileFieldError();
		if (updateFileErrorCode > 0) {
			if (updateFileErrorCode == 1) {
				res.getData().put("code", "3");
				res.getData().put("message",
						"文件上传类型错误,系统只允许上传 jpg,jpeg,gif,png 格式的文件。");
			} else if (updateFileErrorCode == 2) {
				res.getData().put("code", "4");
				res.getData().put("message",
						"上传文件大小错误,系统最多只允许上传大小为100MB的附件，并且附件不能为null。");
			} else {
				res.getData().put("code", "5");
				res.getData().put("message", "上传文件失败,请与系统管理员联系。");
			}
			return renderJson(res);
		}

		String suffix = getFileSuffix(uploadFileName);

		if (!suffix.equals("jpg") && !suffix.equals("jpeg")
				&& !suffix.equals("gif") && !suffix.equals("png")) {
			res.getData().put("code", "3");
			res.getData().put("message",
					"文件上传类型错误,系统只允许上传 jpg,jpeg,gif,png 格式的文件。");
			return renderJson(res);
		}

		if (uploadFileSize > (SystemConstants.FILE_UPLOAD_SIZE)) {
			res.getData().put("code", "4");
			res.getData().put(
					"message",
					"上传文件大小错误,系统最多只允许上传大小为" + SystemConstants.FILE_UPLOAD_SIZE
							+ "B的附件，并且附件不能为null。");
			return renderJson(res);
		}
		res.getData().put("code", "0");
		res.getData().put("url", uploadFileURL);
		// 这里调用，强制输出多个尺寸
		imageUtils.resetImgByWidth(uploadFileURL.replaceFirst(
				SystemConstants.UPLOAD_WEB_URL,
				SystemConstants.UPLOAD_SERVER_PATH));
		return renderJson(res);
	}

	/**
	 * 创建一篇文章
	 */
	@SuppressWarnings("unchecked")
	@Action(value = "/createArticle", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String createArticle() {
		Map<String, Object> user = (Map<String, Object>) getRequest()
				.getSession().getAttribute(SystemConstants.USER_SESSION_KEY);
		String[] imgStrArr = imgStr.split(",");
		String[] imgSummaryStrArr = imgSummaryStr.split(",");
		String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
		if (articleId == null) {
			Map<String, Object> paramMap = new HashMap<String, Object>();
			Map<String, Object> paramMap3 = new HashMap<String, Object>();
			paramMap.put("title", title);
			paramMap.put("authorId", user.get("userId"));
			paramMap3.put("author_type", user.get("groupId"));
			paramMap.put("columnId", columnId);
			paramMap3.put("publish_type",
					ManConstants.ARTICLE_PUBLISHTYPE_GUANFANG);
			paramMap.put("state", ManConstants.ARTICLE_STATE_COMMON);
			paramMap.put("createDate", now);
			paramMap.put("update_time", now);
			paramMap.put("summary", summary);
			paramMap.put("tags", tags);

			articleId = articleService.add(SqlUtils.genderInsertSql(
					"man_base_article", paramMap));
			paramMap3.put("id", articleId);
			articleFieldService.add(SqlUtils.genderInsertSql(
					articleFieldService.getTableName(), paramMap3));
			for (int i = 0; i < imgStrArr.length; i++) {
				String imgTmp = imgStrArr[i];
				String imgSummaryTmp = imgSummaryStrArr[i];
				Map<String, Object> paramMap2 = new HashMap<String, Object>();
				paramMap2.put("articleId", articleId);
				paramMap2.put("imageUrl",
						imgTmp.toLowerCase().startsWith("http:") ? imgTmp
								: SystemConstants.UPLOAD_WEB_URL + imgTmp);
				paramMap2.put("userId", user.get("userId"));
				paramMap2.put("createDate", now);
				paramMap2.put("summary", imgSummaryTmp);
				imageService.add(SqlUtils.genderInsertSql(
						imageService.getTableName(), paramMap2));
			}
		} else {
			// 更新
			Map<String, Object> paramMap = new HashMap<String, Object>();
			Map<String, Object> paramMap3 = new HashMap<String, Object>();
			paramMap.put("title", title);
			paramMap.put("update_time", now);
			paramMap.put("summary", summary);
			paramMap.put("columnId", columnId);
			paramMap3.put("publish_type",
					ManConstants.ARTICLE_PUBLISHTYPE_GUANFANG);
			paramMap.put("tags", tags);
			articleService.update(SqlUtils.genderUpdateSql("man_base_article",
					"id = " + articleId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
			articleFieldService.update(SqlUtils.genderUpdateSql(
					articleFieldService.getTableName(), "id = " + articleId,
					SqlUtils.genderConditionsByType(paramMap3, ",")));
			for (int i = 0; i < imgStrArr.length; i++) {
				String imgTmp = imgStrArr[i];
				String imgSummaryTmp = imgSummaryStrArr[i];
				Map<String, Object> tmp = imageService
						.queryOneRow("select * from "
								+ imageService.getTableName()
								+ " where imageUrl = '" + imgTmp
								+ "' and userId = '" + user.get("userId") + "'");
				if (tmp != null && tmp.size() > 0) {
					Map<String, Object> paramMap2 = new HashMap<String, Object>();
					paramMap2.put("articleId", articleId);
					paramMap2.put("imageUrl",
							imgTmp.toLowerCase().startsWith("http:") ? imgTmp
									: SystemConstants.UPLOAD_WEB_URL + imgTmp);
					paramMap2.put("userId", user.get("userId"));
					paramMap2.put("summary", imgSummaryTmp);
					imageService.update(SqlUtils.genderUpdateSql(
							imageService.getTableName(),
							"imageUrl = '" + imgTmp + "' and userId = '"
									+ user.get("userId") + "'",
							SqlUtils.genderConditionsByType(paramMap2, ",")));
				} else {
					Map<String, Object> paramMap2 = new HashMap<String, Object>();
					paramMap2.put("articleId", articleId);
					paramMap2.put("imageUrl",
							imgTmp.toLowerCase().startsWith("http:") ? imgTmp
									: SystemConstants.UPLOAD_WEB_URL + imgTmp);
					paramMap2.put("userId", user.get("userId"));
					paramMap2.put("createDate", now);
					paramMap2.put("summary", imgSummaryTmp);
					imageService.add(SqlUtils.genderInsertSql(
							imageService.getTableName(), paramMap2));
				}
			}
		}
		Cache.removeKeyByContainStr(articleService.getTableName());
		Cache.removeKeyByContainStr(articleFieldService.getTableName());
		JsonSuccessResponse res = new JsonSuccessResponse();
		res.getData().put("code", "0");
		return renderJson(res);
	}

	/**
	 * 删除一张文章的图片
	 */
	@Action(value = "/delArticleImg", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String delArticleImg() {
		imageService.excute("delete from " + imageService.getTableName()
				+ "  where imageUrl = '" + imgPath + "' and articleId = '"
				+ articleId + "'");
		JsonSuccessResponse res = new JsonSuccessResponse();
		res.getData().put("code", "0");
		return renderJson(res);
	}

	/**
	 * 文章上线
	 */
	@SuppressWarnings("unchecked")
	@Action(value = "/articleUp", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String articleUp() {
		Map<String, Object> user = (Map<String, Object>) getRequest()
				.getSession().getAttribute(SystemConstants.USER_SESSION_KEY);
		String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
		Map<String, Object> paramMap = new HashMap<String, Object>();
		Map<String, Object> paramMap2 = new HashMap<String, Object>();
		paramMap.put("state", ManConstants.ARTICLE_STATE_UP);
		paramMap2.put("audit_id", user.get("userId"));
		paramMap2.put("audit_time", now);
		if (StringUtils.isEmpty(publishTime)) {
			paramMap.put("publish_time", now);
		} else {
			paramMap.put("publish_time", publishTime);
		}
		articleService.update(SqlUtils.genderUpdateSql("man_base_article",
				"id = " + articleId,
				SqlUtils.genderConditionsByType(paramMap, ",")));
		articleFieldService.update(SqlUtils.genderUpdateSql(
				articleFieldService.getTableName(), "id = " + articleId,
				SqlUtils.genderConditionsByType(paramMap2, ",")));
		Cache.removeKeyByContainStr(articleService.getTableName());
		Cache.removeKeyByContainStr(articleFieldService.getTableName());
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("state", 0);
		return renderJson(resultMap);
	}

	/**
	 * 文章下线
	 */
	@SuppressWarnings("unchecked")
	@Action(value = "/articleDown", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String articleDown() {
		Map<String, Object> user = (Map<String, Object>) getRequest()
				.getSession().getAttribute(SystemConstants.USER_SESSION_KEY);
		String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
		Map<String, Object> paramMap2 = new HashMap<String, Object>();
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("state", ManConstants.ARTICLE_STATE_DOWN);
		paramMap2.put("audit_id", user.get("userId"));
		paramMap2.put("audit_time", now);
		paramMap.put("publish_time", now);
		articleService.update(SqlUtils.genderUpdateSql("man_base_article",
				"id = " + articleId,
				SqlUtils.genderConditionsByType(paramMap, ",")));
		articleFieldService.update(SqlUtils.genderUpdateSql(
				articleFieldService.getTableName(), "id = " + articleId,
				SqlUtils.genderConditionsByType(paramMap2, ",")));
		Cache.removeKeyByContainStr(articleService.getTableName());
		Cache.removeKeyByContainStr(articleFieldService.getTableName());
		return chain("/manage/viewArticlePage");
	}

	/**
	 * 文章置顶
	 */
	@Action(value = "/articleTop", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String articleTop() {
		String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("top_time", now);
		articleService.update(SqlUtils.genderUpdateSql("man_base_article",
				"id = " + articleId,
				SqlUtils.genderConditionsByType(paramMap, ",")));
		Cache.removeKeyByContainStr("man_base_article");
		return chain("/manage/viewArticlePage");
	}

	/**
	 * 文章推荐
	 */
	@SuppressWarnings("unchecked")
	@Action(value = "/articleRecommend", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String articleRecommend() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("recommend", ManConstants.ARTICLE_RECOMMEND_OK);
		articleService.update(SqlUtils.genderUpdateSql("man_base_article",
				"id = " + articleId,
				SqlUtils.genderConditionsByType(paramMap, ",")));
		Cache.removeKeyByContainStr(articleService.getTableName());
		return chain("/manage/viewArticlePage");
	}

	/**
	 * 文章取消推荐
	 */
	@SuppressWarnings("unchecked")
	@Action(value = "/articleUnRecommend", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String articleUnRecommend() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("recommend", ManConstants.ARTICLE_RECOMMEND_FAIL);
		articleService.update(SqlUtils.genderUpdateSql("man_base_article",
				"id = " + articleId,
				SqlUtils.genderConditionsByType(paramMap, ",")));
		Cache.removeKeyByContainStr(articleService.getTableName());
		return chain("/manage/viewArticlePage");
	}

	/**
	 * 通过装女郎申请
	 */
	@Action(value = "/applyUser", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String applyUser() {
		Map<String, Object> userApply = userApplyService.queryById(applyId);
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, Object> params2 = new HashMap<String, Object>();
		params2.put("age", userApply.get("age"));
		params2.put("bust", userApply.get("bust"));
		params2.put("waistline", userApply.get("waistline"));
		params2.put("hip", userApply.get("hip"));
		params2.put("bwh", userApply.get("bwh"));
		params2.put("constellation", userApply.get("constellation"));
		params2.put("pkImageUrl", userApply.get("iconUrl"));
		params2.put("pkBigImageUrl", userApply.get("imageUrl"));
		params2.put("girlCity", userApply.get("girlCity"));
		params.put("groupId", ManConstants.USER_TYPE_ZHUANGNVLANG);

		userService.update(SqlUtils.genderUpdateSql("man_base_user",
				"userId = " + userApply.get("userId"),
				SqlUtils.genderConditionsByType(params, ",")));
		userFieldService.update(SqlUtils.genderUpdateSql(
				userFieldService.getTableName(),
				"userId = " + userApply.get("userId"),
				SqlUtils.genderConditionsByType(params2, ",")));
		Cache.removeKeyByContainStr("man_base_user");
		userApplyService.update("update man_base_user_apply set state = "
				+ ManConstants.GIRL_APPLY_OK + ",applyDate = '"
				+ MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss")
				+ "' where id = " + applyId);
		// TODO
		// 如果需要获取那些数据位0的装女郎到榜单中，给投票表中初始化一条为0的记录，投票人的id为-1这个特殊值，主要是方便获取相关的投票人信息
		Map<String, Object> params3 = new HashMap<String, Object>();
		params3.put("userId", 1);// 管理员的id
		params3.put("girlId", userApply.get("userId"));
		params3.put("createDate",
				MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
		params3.put("voteNum", 0);
		params3.put("createDay", MyDateUtils.parseDateToStr("yyyy-MM-dd"));
		voteService.add(SqlUtils.genderInsertSql(voteService.getTableName(),
				params3));
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("state", 0);
		resultMap.put("msg", "操作成功");
		return renderJson(resultMap);
	}

	/**
	 * 拒绝通过装女郎申请
	 */
	@Action(value = "/unapplyUser", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String unapplyUser() {
		userApplyService.update("update man_base_user_apply set state = "
				+ ManConstants.GIRL_APPLY_FAIL + ",applyDate = '"
				+ MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss")
				+ "' where id = " + applyId);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("state", 0);
		resultMap.put("msg", "操作成功");
		return renderJson(resultMap);
	}

	/**
	 * 进入装女郎申请列表分页
	 */
	@Action(value = "/viewUserZhuangnvlangApplyPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewUserZhuangnvlangApplyPage() {
		return dispatcher("/userZhuangnvlangApplyList.jsp");
	}

	/**
	 * 获取装女郎申请列表分页的json
	 */
	@Action(value = "/mUserZhuangnvlangApplyPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mUserZhuangnvlangApplyPage() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		if (!StringUtils.isEmpty(name)) {
			paramMap.put("name like ", "%" + name + "%");
		}
		if (!StringUtils.isEmpty(girlCity)) {
			paramMap.put("girlCity like ", "%" + girlCity + "%");
		}
		String sql = SqlUtils.genderQuerySql("man_base_user_apply",
				SqlUtils.genderConditionsByType(paramMap, "and"));
		Page page = new Page(pageNumber, pageLine, sql, "0s", userApplyService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 进入装女郎列表分页
	 */
	@Action(value = "/viewUserZhuangnvlangPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewUserZhuangnvlangPage() {
		return dispatcher("/userZhuangnvlangList.jsp");
	}

	/**
	 * 获取装女郎列表分页的json
	 */
	@Action(value = "/mUserZhuangnvlangPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mUserZhuangnvlangPage() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		if (type != null) {
			if (type.intValue() == ManConstants.BANGDAN_TYPE_HOT.intValue()) {
				paramMap.put("userType", ManConstants.USER_TYPE_ZHUANGNVLANG);
			}
			if (type.intValue() == ManConstants.BANGDAN_TYPE_CITY.intValue()) {
				paramMap.put("userType", ManConstants.USER_TYPE_ZHUANGNVLANG);
			}
			if (type.intValue() == ManConstants.BANGDAN_TYPE_MINGREN.intValue()) {
				paramMap.put("userType", ManConstants.USER_TYPE_MINGREN);
			}
		}
		if (!StringUtils.isEmpty(userState)) {
			paramMap.put("state", userState);
		}
		if (!StringUtils.isEmpty(name)) {
			paramMap.put("name like ", "%" + name + "%");
		}
		if (days != null) {
			// 计算出多少天前对应的时间
			String startDate = MyDateUtils.parseDateToStr(
					MyDateUtils.addDate(-days), "yyyy-MM-dd");
			paramMap.put("voteDate >=", startDate);
		}

		String sql = "select *,sum(voteNum) as votes from man_view_bangdan where "
				+ SqlUtils.genderConditionsByType(paramMap, "and")
				+ " group by id order by votes,score desc";
		Page page = new Page(pageNumber, pageLine, sql, expire,
				viewBangdanService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 进入用户列表分页
	 */
	@Action(value = "/viewUserPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String viewUserPage() {
		return dispatcher("/userList.jsp");
	}

	/**
	 * 获取用户列表分页的json
	 */
	@Action(value = "/mUserPage", interceptorRefs = @InterceptorRef("withAuthStack"))
	public String mUserPage() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		if (!StringUtils.isEmpty(userType)) {
			paramMap.put("groupId", userType);
		}
		if (!StringUtils.isEmpty(userState)) {
			paramMap.put("state", userState);
		}
		if (!StringUtils.isEmpty(name)) {
			paramMap.put("name like ", "%" + name + "%");
		}
		String addStr = "";
		String sqls = "select * from "
				+ viewBaseuserUnionService.getTableName() + " where  " + addStr
				+ SqlUtils.genderConditionsByType(paramMap, "and ")
				+ " order by createDate desc";
		Page page = new Page(pageNumber, pageLine, sqls, expire, userService);
		return renderJson(page.getResultMap());
	}

	/**
	 * 进入创建新用户
	 */
	@Action(value = "/viewCreateUser", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String viewCreateUser() {
		if (userId != null) {
			Map<String, Object> user = viewBaseuserUnionService
					.queryOneRow("select * from "
							+ viewBaseuserUnionService.getTableName()
							+ " where userId = " + userId);
			getRequest().setAttribute("modifyUser", user);
		}
		if (zhuangnvlangList != null) {
			getRequest().setAttribute("zhuangnvlangList", zhuangnvlangList);
		}
		return dispatcher("/user.jsp");
	}

	/**
	 * 修改用户
	 */
	@Action(value = "/modifyUser", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String modifyUser() {
		Map<String, Object> result = new HashMap<String, Object>();
		// || StringUtils.isEmpty(password)
		if (StringUtils.isEmpty(userName)) {
			result.put("state", -1);
			result.put("msg", "关键参数不能为空");
			return renderJson(result);
		}
		if (userId == null) {
			Map<String, Object> tmp = userService.queryOneRow(SqlUtils
					.genderQuerySql("man_view_baseuser_union", "userName = '"
							+ userName + "'"));
			if (tmp != null && tmp.size() > 0) {
				result.put("state", -2);
				result.put("msg", "该同名账号已存在，请换一个其他账号");
				return renderJson(result);
			}
		}
		// 这里要操作两个表了。
		String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userName", userName);
		if (userId != null) {
			Map<String, Object> userBefore = viewBaseuserUnionService
					.queryOneRow("select * from "
							+ viewBaseuserUnionService.getTableName()
							+ " where userId = " + userId);
			if (!(userBefore.get("password") + "").equals(password)) {
				paramMap.put("password", MD5Util.getMD5Lower(password));
			}
		} else {
			paramMap.put("password", MD5Util.getMD5Lower(password));
		}
		paramMap.put("name", name);
		paramMap.put("groupId", userType);
		paramMap.put("phone", phoneNumber);
		paramMap.put("update_time", now);
		paramMap.put("imageUrl", imageUrl);

		Map<String, Object> paramMap2 = new HashMap<String, Object>();
		paramMap2.put("bwh", bwh);
		paramMap2.put("bust", bust);
		paramMap2.put("waistline", waistline);
		paramMap2.put("hip", hip);
		paramMap2.put("gender", gender);
		paramMap2.put("age", age);
		paramMap2.put("girlWeight", girlWeight);
		paramMap2.put("girlPkWeight", girlPkWeight);
		paramMap2.put("phoneNumber", phoneNumber);
		paramMap2.put("introduction", " ");

		paramMap2.put("pkImageUrl", pkImageUrl);
		paramMap2.put("pkBigImageUrl", pkBigImageUrl);
		if (!StringUtils.isEmpty(score)) {
			paramMap2.put("score", score);
		}

		if (userId == null) {
			paramMap.put("createDate", now);
			paramMap.put("state", ManConstants.USER_STATE_COMMON);
			userId = userService.add(SqlUtils.genderInsertSql(
					userService.getTableName(), paramMap));
			paramMap2.put("userId", userId);
			userFieldService.add(SqlUtils.genderInsertSql(
					userFieldService.getTableName(), paramMap2));
			// 强制定义装女郎的类型为2
			if (userType.equals("2")) {
				// TODO
				// 如果需要获取那些数据位0的装女郎到榜单中，给投票表中初始化一条为0的记录，投票人的id为-1这个特殊值，主要是方便获取相关的投票人信息
				Map<String, Object> params3 = new HashMap<String, Object>();
				params3.put("userId", 1);// 管理员的id
				params3.put("girlId", userId);
				params3.put("createDate",
						MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
				params3.put("voteNum", 0);
				params3.put("createDay",
						MyDateUtils.parseDateToStr("yyyy-MM-dd"));
				voteService.add(SqlUtils.genderInsertSql(
						voteService.getTableName(), params3));
			}
		} else {
			if (!StringUtils.isEmpty(createDate)) {
				paramMap.put("createDate", createDate);
			}
			userService.update(SqlUtils.genderUpdateSql(
					userService.getTableName(), "userId = " + userId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
			userFieldService.update(SqlUtils.genderUpdateSql(
					userFieldService.getTableName(), "userId = " + userId,
					SqlUtils.genderConditionsByType(paramMap2, ",")));
		}

		result.put("state", 0);
		result.put("msg", "操作成功");
		Cache.removeKeyByContainStr(userService.getTableName());
		Cache.removeKeyByContainStr(userFieldService.getTableName());
		Cache.removeKeyByContainStr(viewBaseuserUnionService.getTableName());
		return renderJson(result);
	}

	/**
	 * 冻结用户积分
	 */
	@Action(value = "/freezeScore", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String freezeScore() {
		Map<String, Object> result = new HashMap<String, Object>();
		String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
		Map<String, Object> paramMap = new HashMap<String, Object>();
		Map<String, Object> paramMap2 = new HashMap<String, Object>();
		if (userId != null) {
			paramMap2.put("update_time", now);
			userService.update(SqlUtils.genderUpdateSql(
					userService.getTableName(), "userId = " + userId,
					SqlUtils.genderConditionsByType(paramMap2, ",")));
			paramMap.put("scoreState", ManConstants.USER_SCORE_FREEZE);
			userFieldService.update(SqlUtils.genderUpdateSql(
					userFieldService.getTableName(), "userId = " + userId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
		}
		result.put("state", 0);
		result.put("msg", "操作成功");
		Cache.removeKeyByContainStr(userFieldService.getTableName());
		return renderJson(result);
	}

	/**
	 * 取消冻结用户积分
	 */
	@Action(value = "/unfreezeScore", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String unfreezeScore() {
		Map<String, Object> result = new HashMap<String, Object>();
		String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
		Map<String, Object> paramMap = new HashMap<String, Object>();
		Map<String, Object> paramMap2 = new HashMap<String, Object>();
		if (userId != null) {
			paramMap2.put("update_time", now);
			userService.update(SqlUtils.genderUpdateSql(
					userService.getTableName(), "userId = " + userId,
					SqlUtils.genderConditionsByType(paramMap2, ",")));
			paramMap.put("scoreState", ManConstants.USER_SCORE_UNFREEZE);
			userFieldService.update(SqlUtils.genderUpdateSql(
					userFieldService.getTableName(), "userId = " + userId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
		}
		result.put("state", 0);
		result.put("msg", "操作成功");
		Cache.removeKeyByContainStr(userFieldService.getTableName());
		return renderJson(result);
	}

	/**
	 * 删除用户
	 */
	@Action(value = "/delUser", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String delUser() {
		Map<String, Object> result = new HashMap<String, Object>();
		if (userId != null) {
			userService.excute("delete from " + userService.getTableName()
					+ " where userId = " + userId);
			userFieldService.excute("delete from "
					+ userFieldService.getTableName() + " where userId = "
					+ userId);
		}
		result.put("state", 0);
		result.put("msg", "操作成功");
		Cache.removeKeyByContainStr("man_base_user");
		return renderJson(result);
	}

	/**
	 * 禁用用户
	 */
	@Action(value = "/disableUser", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String disableUser() {
		Map<String, Object> result = new HashMap<String, Object>();
		String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
		Map<String, Object> paramMap = new HashMap<String, Object>();
		Map<String, Object> paramMap2 = new HashMap<String, Object>();
		if (userId != null) {
			paramMap2.put("update_time", now);
			userService.update(SqlUtils.genderUpdateSql(
					userService.getTableName(), "userId = " + userId,
					SqlUtils.genderConditionsByType(paramMap2, ",")));
			paramMap.put("state", ManConstants.USER_STATE_STOP);
			userService.update(SqlUtils.genderUpdateSql("man_base_user",
					"userId = " + userId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
		}
		result.put("state", 0);
		result.put("msg", "操作成功");
		Cache.removeKeyByContainStr("man_base_user");
		return renderJson(result);
	}

	/**
	 * 取消禁用用户
	 */
	@Action(value = "/undisableUser", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String undisableUser() {
		Map<String, Object> result = new HashMap<String, Object>();
		String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
		Map<String, Object> paramMap = new HashMap<String, Object>();
		Map<String, Object> paramMap2 = new HashMap<String, Object>();
		if (userId != null) {
			paramMap2.put("update_time", now);
			userService.update(SqlUtils.genderUpdateSql(
					userService.getTableName(), "userId = " + userId,
					SqlUtils.genderConditionsByType(paramMap2, ",")));
			paramMap.put("state", ManConstants.USER_STATE_COMMON);
			userService.update(SqlUtils.genderUpdateSql("man_base_user",
					"userId = " + userId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
		}
		result.put("state", 0);
		result.put("msg", "操作成功");
		Cache.removeKeyByContainStr("man_base_user");
		return renderJson(result);
	}

	/**
	 * 进入修改密码
	 */
	@Action(value = "/viewModifyPwd", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String viewModifyPwd() {
		return dispatcher("/pwd.jsp");
	}

	/**
	 * 修改密码
	 */
	@SuppressWarnings("unchecked")
	@Action(value = "/modifyPwd", interceptorRefs = @InterceptorRef("withUploadStack"))
	public String modifyPwd() {
		Map<String, Object> user = (Map<String, Object>) getRequest()
				.getSession().getAttribute(SystemConstants.USER_SESSION_KEY);
		Map<String, Object> result = new HashMap<String, Object>();
		if (StringUtils.isEmpty(oldpwd)
				|| !MD5Util.getMD5Lower(oldpwd).equals(
						user.get("password") + "")) {
			result.put("state", -1);
			result.put("msg", "原始密码不正确，请重新输入");
			return renderJson(result);
		}
		if (StringUtils.isEmpty(newpwd)) {
			result.put("state", -2);
			result.put("msg", "新密码不能为空，请重新输入");
			return renderJson(result);
		}
		userService.update("update man_base_user set password = '"
				+ MD5Util.getMD5Lower(newpwd) + "' where userId = "
				+ user.get("userId"));
		result.put("state", 0);
		result.put("msg", "密码修改成功");
		getSession().setAttribute(
				SystemConstants.USER_SESSION_KEY,
				viewBaseuserUnionService.queryOneRow(SqlUtils.genderQuerySql(
						viewBaseuserUnionService.getTableName(), "userId = "
								+ user.get("userId"))));
		return renderJson(result);
	}

	public void setParamMap(Map<String, Object> paramMap) {
		this.paramMap = paramMap;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setGender(Integer gender) {
		this.gender = gender;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public void setBwh(String bwh) {
		this.bwh = bwh;
	}

	public void setConstellation(String constellation) {
		this.constellation = constellation;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setPlatform(String platform) {
		this.platform = platform;
	}

	public void setPageNumber(Integer pageNumber) {
		this.pageNumber = pageNumber;
	}

	public void setPageLine(Integer pageLine) {
		this.pageLine = pageLine;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public void setFomart(String fomart) {
		this.fomart = fomart;
	}

	public void setImages(String[] images) {
		this.images = images;
	}

	public void setAlbumId(Long albumId) {
		this.albumId = albumId;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public void setFollowUserId(Long followUserId) {
		this.followUserId = followUserId;
	}

	public void setValue(Boolean value) {
		this.value = value;
	}

	public void setColumnId(Long columnId) {
		this.columnId = columnId;
	}

	public void setArticleId(Long articleId) {
		this.articleId = articleId;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public void setQuestionId(Long questionId) {
		this.questionId = questionId;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public void setFujianFile(File fujianFile) {
		this.fujianFile = fujianFile;
	}

	public void setFujianFileFileName(String fujianFileFileName) {
		this.fujianFileFileName = fujianFileFileName;
	}

	public void setFujianFileContentType(String fujianFileContentType) {
		this.fujianFileContentType = fujianFileContentType;
	}

	public void setUploadFileURL(String uploadFileURL) {
		this.uploadFileURL = uploadFileURL;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public void setUploadFileSize(Integer uploadFileSize) {
		this.uploadFileSize = uploadFileSize;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setImgStr(String imgStr) {
		this.imgStr = imgStr;
	}

	public void setImgPath(String imgPath) {
		this.imgPath = imgPath;
	}

	public void setImgSummaryStr(String imgSummaryStr) {
		this.imgSummaryStr = imgSummaryStr;
	}

	public void setOldpwd(String oldpwd) {
		this.oldpwd = oldpwd;
	}

	public void setNewpwd(String newpwd) {
		this.newpwd = newpwd;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	public void setPublishType(String publishType) {
		this.publishType = publishType;
	}

	public void setPublishTime(String publishTime) {
		this.publishTime = publishTime;
	}

	public void setUserState(String userState) {
		this.userState = userState;
	}

	public void setGirlCity(String girlCity) {
		this.girlCity = girlCity;
	}

	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}

	public void setScore(String score) {
		this.score = score;
	}

	public void setGirlWeight(String girlWeight) {
		this.girlWeight = girlWeight;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public void setDays(Integer days) {
		this.days = days;
	}

	public void setZhuangnvlangList(String zhuangnvlangList) {
		this.zhuangnvlangList = zhuangnvlangList;
	}

	public void setGirlPkWeight(String girlPkWeight) {
		this.girlPkWeight = girlPkWeight;
	}

	public void setApplyId(Long applyId) {
		this.applyId = applyId;
	}

	public void setFmId(Long fmId) {
		this.fmId = fmId;
	}

	public void setFmUrl(String fmUrl) {
		this.fmUrl = fmUrl;
	}

	public void setIconUrl(String iconUrl) {
		this.iconUrl = iconUrl;
	}

	public void setStaticOrderType(String staticOrderType) {
		this.staticOrderType = staticOrderType;
	}

	public void setCommentId(Long commentId) {
		this.commentId = commentId;
	}

	public void setQuestId(Long questId) {
		this.questId = questId;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public void setQuestProcess(Integer questProcess) {
		this.questProcess = questProcess;
	}

	public void setScoreRuleId(Long scoreRuleId) {
		this.scoreRuleId = scoreRuleId;
	}

	public void setTagId(Long tagId) {
		this.tagId = tagId;
	}

	public void setImageUrl(String imageUrl) {
		this.imageUrl = imageUrl;
	}

	public void setPkImageUrl(String pkImageUrl) {
		this.pkImageUrl = pkImageUrl;
	}

	public void setPkBigImageUrl(String pkBigImageUrl) {
		this.pkBigImageUrl = pkBigImageUrl;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public void setBust(Integer bust) {
		this.bust = bust;
	}

	public void setWaistline(Integer waistline) {
		this.waistline = waistline;
	}

	public void setHip(Integer hip) {
		this.hip = hip;
	}

	public void setAdsId(Long adsId) {
		this.adsId = adsId;
	}

	public void setAdsClass(String adsClass) {
		this.adsClass = adsClass;
	}

	public void setAdsUrl(String adsUrl) {
		this.adsUrl = adsUrl;
	}

	public void setAdsHtml(String adsHtml) {
		this.adsHtml = adsHtml;
	}

	public void setAdsPic(String adsPic) {
		this.adsPic = adsPic;
	}

	public void setTags(String tags) {
		this.tags = tags;
	}

	public void setQuestionType(Integer questionType) {
		this.questionType = questionType;
	}

	public void setUserGroupId(Long userGroupId) {
		this.userGroupId = userGroupId;
	}

	public void setUserGroupName(String userGroupName) {
		this.userGroupName = userGroupName;
	}

	public void setFilterId(Long filterId) {
		this.filterId = filterId;
	}

	public void setFilterKeyStr(String filterKeyStr) {
		this.filterKeyStr = filterKeyStr;
	}

	public void setScoreRuleName(String scoreRuleName) {
		this.scoreRuleName = scoreRuleName;
	}

	public void setScoreRuleAction(String scoreRuleAction) {
		this.scoreRuleAction = scoreRuleAction;
	}

}
